package com.LeetCode.doublePair;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashSet;

/**
 * 最长无重复子串长度
 */
public class maxSetLength {

    /**
     *
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxLength (int[] arr) {
        HashSet<Integer> set = new HashSet<>();
        int res = 0;
        int l = 0, r = 0;
        while(r < arr.length){
            if(!set.contains(arr[r])){
                set.add(arr[r]);
                r++;
            }else{
                set.remove(arr[l]);
                l++;
            }
            res = Math.max(res, set.size());
        }
        return res;
    }

    @Test
    public void test(){
        int[] arr = {2,2,3,4,3};
        System.out.println(maxLength(arr));
    }
}
